package com.eptok.weixin.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class StrUtil {

	/**
	 *@desc:  取字符串的Unicode编码长度，返回格式固定10位长度的数字字符串，位数不足补0
	 * */
	public static String getStrUnicodeLength(String string) 
	{
		String returnString ="0";
		
		try
		{
			returnString = String.format("%1$010d", new String(string.getBytes(), "US-ASCII").length());
		}
		catch (Exception e)
		{
			// TODO: handle exception
			returnString = String.format("%1$010d", returnString);
		}
		
		return returnString;
	}

	
	public static Map parse(String result) {   
		Map map = new HashMap();
		
		JSONObject osonObj = JSONObject.parseObject(result);
        JSONObject contentJson = JSONObject.parseObject(osonObj.getString("result"));
        JSONObject locationStr = JSONObject.parseObject(contentJson.getString("addressComponent"));
        String province = locationStr.getString("province");
        String city = locationStr.getString("city");
        map.put("province", province);
        map.put("city", city);
        List<String> l = new ArrayList<String>();
        JSONArray poisStr = JSONObject.parseArray(contentJson.getString("pois"));
        for(int i=0;i<poisStr.size();i++){
        	JSONObject myJSONObject = poisStr.getJSONObject(i);
        	String addr = myJSONObject.getString("addr");
        	String name = myJSONObject.getString("name");
        	l.add(addr+name);
        }
        map.put("list", l);
        return map;
	}
	
}
